<template>
  <div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="modelFormHandle()" type="primary" icon="plus">新增</a-button>
      <a-button
          @click="batchDeleteHandle"
          v-if="selectedRowKeys.length > 0"
          ghost
          type="primary"
          icon="delete">批量删除
      </a-button>
    </div>

    <!-- table区域-begin -->
    <div>

      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{
          selectedRowKeys.length
        }}</a>项&nbsp;&nbsp;
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
          rowKey="id"
          :columns="columns"
          size="middle"
          :pagination="false"
          :dataSource="dataList"
          :loading="loading"
          :expandedRowKeys="expandedRowKeys"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @expandedRowsChange="handleExpandedRowsChange">

          <span slot="action" slot-scope="text, record">
            <a @click="modelFormHandle(record.id)">编辑</a>

            <a-divider type="vertical" />
            <a-dropdown>
              <a class="ant-dropdown-link">
                更多 <a-icon type="down" />
              </a>
              <a-menu slot="overlay">
                <a-menu-item>
                  <a href="javascript:;" @click="modelFormSubHandle(record.id)">添加下级</a>
                </a-menu-item>

                <a-menu-item>
                  <a-popconfirm title="确定删除吗?" @confirm="() => deleteHandle(record.id)">
                    <a>删除</a>
                  </a-popconfirm>
                </a-menu-item>
              </a-menu>
            </a-dropdown>
          </span>
      </a-table>

    </div>
    <!-- table区域-end -->

    <model-form ref="modelForm" v-if="modelFormVisible" @ok="modalFormOk"></model-form>
  </div>
</template>

<script>
import listMixin from '@/mixins/list-mixin'
import modelForm from './model/menu-form'

export default {
  name: "menu",
  mixins: [listMixin],
  components: {
    modelForm
  },
  data () {
    return {
      disableMixinCreated: true,
      modelFormVisible: false,
      expandedRowKeys: [],
      columns: [
        {
          title: '菜单名称',
          dataIndex: 'name',
          key: 'name'
        },
        {
          title: '菜单类型',
          dataIndex: 'type',
          key: 'type',
          customRender: function (text) {
            if (text === 0) {
              return '菜单'
            } else if (text === 1) {
              return '按钮'
            } else {
              return text
            }
          }
        },
        {
          title: 'icon',
          dataIndex: 'icon',
          key: 'icon'
        },
        {
          title: '菜单路由',
          dataIndex: 'url',
          key: 'url'
        },
        {
          title: '授权标识',
          dataIndex: 'permissions',
          key: 'permissions'
        },
        {
          title: '排序',
          dataIndex: 'sort',
          key: 'sort'
        },
        {
          title: '操作',
          dataIndex: 'action',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
          align: 'center',
          width: 150
        }
      ],
      url: {
        list: '/sys/menu/list',
        delete: '/sys/menu',
      }
    }
  },
  methods: {
    handleExpandedRowsChange (expandedRows) {
      this.expandedRowKeys = expandedRows
    },
    modelFormSubHandle(id) {
      this.modelFormVisible = true
      this.$nextTick(() => {
        this.$refs.modelForm.init()
        this.$refs.modelForm.dataForm.pid = id
      })
    }
  }
}
</script>

<style scoped>

</style>
